<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<title>新增申请</title>
<meta name="keyword" content="拖拽式表单设计器,Web Formbuilder,Formbuild,专业表单设计器,高级表单设计器,智能表单设计器,WEB表单设计器,web formdesign,formdesigner">
<meta name="description" content="拖拽式表单设计器Formbuild是强大的在线WEB表单设计器，它通常在、OA系统、问卷调查系统、考试系统、等领域发挥着重要作用，你可以在此基础上任意修改使功能无限强大！">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="author" content="leipi.org">
<link href="${pageContext.request.contextPath}/Public/css/bootstrap/css/bootstrap.css?2024" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/Public/css/site.css?2024" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/toastr.min.css" rel="stylesheet" type="text/css" />
<style type="text/css">
	#components {
		min-height: 600px;
	}
	
	#fm {
		min-height: 200px;
		border: 1px solid #ccc;
		padding: 5px;
	}
	
	#fm .component {
		border: 1px solid #fff;
	}
	
	#temp {
		width: 500px;
		background: white;
		border: 1px dotted #ccc;
		border-radius: 10px;
	}
	
	.popover-content form {
		margin: 0 auto;
		width: 213px;
	}
	
	.popover-content form .btn {
		margin-right: 10px
	}
	
	#source {
		min-height: 500px;
	}
</style>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/zc/jquery-1.6.2.min.js"></script>
<!--link href="${pageContext.request.contextPath}/Public/css/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet"-->
<script type="text/javascript">
	$(function(){
		//页面加载查询所有部门
		$.ajax({
	        type: 'POST',
	        url: '${pageContext.request.contextPath}/approval/queryAllDept.do',
	        dataType: 'json',
	        success: function (data){
	            for (var i = 0; i < data.length; i++) {
	                $("#dept").append("<option id='"+ data[i].did +"' value='"+ data[i].dname +"'>"+ data[i].dname +"</option>");
	            }
	            var res='';
	            var count = 0;
	            $("#dept").on("click",function(){
	            	if ($(this).val() == '财务部' && $("#appendDept").val() == '') {
	            		toastr.warning('第一个不能选择财务部！');
					} else {
						if ($(this).val() == '财务部') {
							$("#dept").attr("disabled", true);
						}
						var did = $("#dept option:selected")[0].id;
						var value = $(this).val();
		            	$.ajax({
		        	        type: 'POST',
		        	        url: '${pageContext.request.contextPath}/approval/findStaffCountByDid.do?did='+did,
		        	        dataType: 'json',
		        	        success: function (data){
		        	        	if (data == 1) {
		        	        		count ++;
		    		            	if (count == 1) {
		    		            		res += value;
		    			            	$("#appendDept").val(res);
		    			            	$("#dept option:selected").attr("disabled", true);
		    						} else {
		    							res += '—>'+value;
		    			            	$("#appendDept").val(res);
		    			            	$("#dept option:selected").attr("disabled", true);
		    						}
		    		            	if (count == 4) {
		    		            		$("#dept").attr("disabled", true);
		    						}
								} else {
									toastr.warning('该部门没有员工！');
								}
		        	        }
		            	});
					}
	    		})
	        }
        });
	});
</script>
</head>
<body>
	<div class="container">
		<div class="row clearfix">
			<div class="span6">
				<div class="clearfix" style="position: relative;">
					<h2 style="text-align: center;">${model1.mName }</h2>
					<hr>
					<form id="fm" class="form-horizontal">
						<div id="legend">
							<input type="hidden" id="mFields" name="mFields" value="${model1.mFields }">
							<input type="hidden" id="status03" name="status03" value="${model1.mName }">
							<%-- 
								<c:forEach items="${model.mFieldList }" var="modelField">
									<div class="control-group">
										<!-- Text -->
										<label class="control-label leipiplugins-orgname">${modelField}</label>
										<div class="controls">
											<input name="modelValue" type="text" placeholder="请输入${modelField}" class="leipiplugins">
										</div>
									</div>
								</c:forEach> 
							--%>
							<c:forEach items="${model}" var="modelMap">
								<c:if test="${modelMap.value == '1' }">
									<div class="control-group">
										<!-- Text -->
										<label class="control-label leipiplugins-orgname">${modelMap.key}</label>
										<div class="controls">
											<input name="modelValue" type="text" placeholder="请输入${modelMap.key}" class="leipiplugins">
										</div>
									</div>
								</c:if>
								<c:if test="${modelMap.value == '2' }">
									<div class="control-group">
										<!-- TextArea -->
										<label class="control-label leipiplugins-orgname">${modelMap.key}</label>
										<div class="textarea">
											<textarea style="margin-left: 20px" name="modelValue" placeholder="请输入${modelMap.key}" class="leipiplugins" leipiplugins="textarea"></textarea>
										</div>
									</div>
								</c:if>
							</c:forEach>
							<select name="dept" id="dept" multiple="multiple" style="margin-left: 180px">
		                        <!-- <option value="">请选择省份</option> -->
		                    </select>
		                    <!-- <select name="city" id="city" multiple="multiple" style="height: 80px">
		                        <option value="">请选择城市</option>
		                    </select> -->
							<!-- <span style="margin-left: 100px; padding-top: 20px">审批顺序</span> -->
							<input type="text" id="appendDept" name="appendDept" readonly="readonly" style="margin-top: 20px;margin-left: 100px; width: 300px">
							<input type="file" id="attachment" name="attachment" style="margin-left: 200px" accept=".doc,.docx">
						</div>
						<div style="position: absolute;bottom: -15px;text-align: center;width: 100%;">
							<button type="button" class="btn btn-primary" id="saveApproval">提交申请</button>&nbsp;&nbsp;&nbsp;&nbsp;
							<button type="reset" class="btn btn-default" id="cleanApproval">重置</button>&nbsp;&nbsp;&nbsp;&nbsp;
							<button type="button" class="btn btn-primary" onclick="history.go(-1)">返回</button>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<!-- /container -->
	<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/Public/js/jquery-1.7.2.min.js?2024"></script>
	<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/Public/js/formbuild/bootstrap/js/bootstrap.min.js?2024"></script>
	<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/Public/js/formbuild/leipi.form.build.core.js?2024"></script>
	<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/Public/js/formbuild/leipi.form.build.plugins.js?2024"></script>
	<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/js/toastr.min.js"></script>
</body>
<script type="text/javascript">
	toastr.options = {  
	    closeButton: false,  
	    debug: false,  
	    progressBar: true,  
	    positionClass: "toast-top-center",  
	    onclick: null,  
	    showDuration: "300",  
	    hideDuration: "1000",  
	    timeOut: "2000",  
	    extendedTimeOut: "1000",  
	    showEasing: "swing",  
	    hideEasing: "linear",  
	    showMethod: "fadeIn",  
	    hideMethod: "fadeOut"  
	};  
</script>
<script type="text/javascript">
	$('#saveApproval').on('click', function() {
		var appendDept = $('#appendDept').val();
		if (appendDept == '') {
			toastr.warning('请选择审批部门！');
			return false;
		}
		var form = new FormData(document.getElementById("fm"));
		$.ajax({
			type : "post",
			url : "${pageContext.request.contextPath}/approval/insertDept.do",
			data : form,
			processData:false,
            contentType:false,
			success : function(data) {
				if(data) {
					toastr.success('提交申请成功！');
					$("#clean").click();
					setTimeout(function(){  //使用  setTimeout（）方法设定定时3000毫秒
						//关闭模态框
						// 父页面刷新
						window.location.reload();  
					},2000);
				} else {
					toastr.warning('提交申请出现错误！');
				}
			},
			error : function () {
				toastr.error('提交申请失败！');
			}
		});
	})
	
	//点击重置后刷新下拉框
	$('#cleanApproval').on('click', function() {
		location.reload();
	})
	
</script>
</html>